using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Admin_Profesores_Profesormaterias : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CboGeneric1.seleciona += seleccion;
        cboMaterias.seleciona += addMateria;
        GridView1.SelectedIndexChanged += new EventHandler(GridView1_SelectedIndexChanged);
        GridView1.RowDeleted += new GridViewDeletedEventHandler(GridView1_RowDeleted);
        GridView1.RowDeleting += new GridViewDeleteEventHandler(GridView1_RowDeleting);
    }

    void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        ProfesorMaterias pf = new ProfesorMaterias();
        pf.IdProfesorMateria = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
        lblMensajes.Text=pf.Borrar();
        FillMaterias(CboGeneric1.Value);
        ShowGridData();
    }

    void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {
          
          
    }

    void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        
        cboMaterias.tabla = "proc_MateriasDisponiblesProfesor" ;
        cboMaterias.TipoOrigen = Controles_cboGeneric.TipoSource.Procedure;
        cboMaterias.BindCBO();
        cboMaterias.Value = GridView1.SelectedValue.ToString();
        cmdOk.Text = "Modificar";
    }

    private void seleccion(string value, string Text)
    {
        FillMaterias(value);
        ShowGridData();
        
    }

    private void FillMaterias(string value)
    {
        cboMaterias.tabla = "proc_MateriasDisponiblesProfesor " + value;
        cboMaterias.TipoOrigen = Controles_cboGeneric.TipoSource.Procedure;
        cboMaterias.BindCBO();
    }
    

    private void ShowGridData()
    {
        GridView1.DataSource = ProfesorMaterias.Tabla("sp_ProfesorMateria " + CboGeneric1.Value);
        GridView1.DataBind();
    }




    private void addMateria(string val, string val1)
    {
       

    }


    protected void cmdOk_Click(object sender, EventArgs e)
    {
        ProfesorMaterias pf = new ProfesorMaterias();
        pf.IdMateria = Convert.ToInt32(cboMaterias.Value);
        pf.IdProfesor = Convert.ToInt32(CboGeneric1.Value);
        pf.Anio = DateTime.Now.Year;
        pf.Activo = 1;
        pf.Crear();
        ShowGridData();
    }
    protected void CboGeneric1_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
    {

    }
}
